﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using hes.models;
using hes.controllers;

namespace hes
{
    public partial class end_term : Form
    {
        public end_term()
        {
            InitializeComponent();
        }

        private void btnEndTerm_Click(object sender, EventArgs e)
        {
            int days;
            try { days = Convert.ToInt32(txtInstructDays.Text); }
            catch { MessageBox.Show("Instructional days must be a valid number"); return; }
            DateTime date = dtpEndDate.Value;
            if (date > DateTime.Now)
            {
                MessageBox.Show("End Date must be today or earlier."); return;
            }

            EndTermController endctrl = new EndTermController();
            int daysneeded = endctrl.NumDays();

            if (daysneeded > days)
            {
                MessageBox.Show(daysneeded + " instructional days are needed. You have " + days);
                return;
            }

            try
            {
                endctrl.EndTerm(date);
                MessageBox.Show("The term has been ended for" +
                SystemController.Instance.CurrentStudent.FirstName + " " +
                SystemController.Instance.CurrentStudent.LastName);
                
                
            }
            catch
            {MessageBox.Show("Term ending failed.");}
            
            this.Close();
        }

        private void btnCancel_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
